package com.exam.serviceimpl;

import com.exam.entity.PaperManage;
import com.exam.mapper.PaperMapper;
import com.exam.service.PaperService;
import com.exam.vo.AnswerVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PaperServiceImpl implements PaperService {

    @Resource
    private PaperMapper paperMapper;
    @Override
    public List<PaperManage> findAll() {
        return paperMapper.findAll();
    }

    @Override
    public List<PaperManage> findById(Integer paperId) {
        return paperMapper.findById(paperId);
    }

    @Override
    public int add(PaperManage paperManage) {
        List<AnswerVO> answerVOS = paperManage.getAnswerVOS();
        for (AnswerVO answerVO : answerVOS) {
            PaperManage paper = new PaperManage();
            paper.setPaperId(paperManage.getPaperId());
            paper.setQuestionId(answerVO.getQuestionId());
            paper.setQuestionType(Integer.parseInt(answerVO.getType()));
            paperMapper.add(paper);
        }
        return 1;
    }

}
